package com.ruoyi.project.meal.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.meal.domain.MealServiceObjectsList;
import com.ruoyi.project.meal.service.IMealServiceObjectsListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务对象报餐明细Controller
 * 
 * @author ruoyi
 * @date 2024-03-07
 */
@Controller
@RequestMapping("/meal/mealList")
public class MealServiceObjectsListController extends BaseController
{
    private String prefix = "meal/mealList";

    @Autowired
    private IMealServiceObjectsListService mealServiceObjectsListService;

    @RequiresPermissions("meal:mealList:view")
    @GetMapping()
    public String mealList()
    {
        return prefix + "/mealList";
    }

    /**
     * 查询服务对象报餐明细列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MealServiceObjectsList mealServiceObjectsList)
    {
        startPage();
        List<MealServiceObjectsList> list = mealServiceObjectsListService.selectMealServiceObjectsListList(mealServiceObjectsList);
        return getDataTable(list);
    }

    /**
     * 导出服务对象报餐明细列表
     */
    @Log(title = "服务对象报餐明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MealServiceObjectsList mealServiceObjectsList)
    {
        List<MealServiceObjectsList> list = mealServiceObjectsListService.selectMealServiceObjectsListList(mealServiceObjectsList);
        ExcelUtil<MealServiceObjectsList> util = new ExcelUtil<MealServiceObjectsList>(MealServiceObjectsList.class);
        return util.exportExcel(list, "服务对象报餐明细数据");
    }

    /**
     * 新增服务对象报餐明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服务对象报餐明细
     */
    @Log(title = "服务对象报餐明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MealServiceObjectsList mealServiceObjectsList)
    {

        return toAjax(mealServiceObjectsListService.insertMealServiceObjectsList(mealServiceObjectsList));
    }

    /**
     * 修改服务对象报餐明细
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        MealServiceObjectsList mealServiceObjectsList = mealServiceObjectsListService.selectMealServiceObjectsListById(id);
        mmap.put("mealServiceObjectsList", mealServiceObjectsList);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务对象报餐明细
     */
    @Log(title = "服务对象报餐明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MealServiceObjectsList mealServiceObjectsList)
    {
        return toAjax(mealServiceObjectsListService.updateMealServiceObjectsList(mealServiceObjectsList));
    }

    /**
     * 删除服务对象报餐明细
     */
    @Log(title = "服务对象报餐明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mealServiceObjectsListService.deleteMealServiceObjectsListByIds(ids));
    }
}
